package com.k12.admim.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.k12.admim.model.vo.TenantVo;
import com.k12.admim.rpc.UserFeignClient;
import com.k12.common.model.resp.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.UUID;

/**
 * 租户控制器
 */
@RestController
public class AdminTenantController {

    @Resource
    private UserFeignClient userFeignClient;


    /**
     * 1、创建租户账号
     * 2、必须是系统管理员身份才能创建租户账号
     */
    @PostMapping("tenant/create")
    @SaCheckRole("super_admin")
    public R<String> createTenantAccount(@RequestBody TenantVo tenantVo) {
        var uuid = UUID.randomUUID();
        tenantVo.setCode(uuid.toString().replaceAll("-", ""));
        Integer result =userFeignClient.createTenantAccount(tenantVo);
        if (result <= 0) {
            return R.failed("相同名称的租户已存在");
        }
        return R.success(uuid.toString());
    }

    public static void main(String[] args) {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));
    }

}
